<template>
  <div class="app-container">
    <el-tabs type="border-card">
      <el-tab-pane label="出场顺序">
        <el-form
          :model="queryParams"
          ref="queryForm"
          size="small"
          :inline="true"
          v-show="showSearch"
          label-width="68px"
        >
          <el-form-item label="场次信息" prop="title">
            <el-input
              v-model="queryParams.title"
              placeholder="请输入场次信息"
              clearable
              @keyup.enter.native="handleQuery"
            />
          </el-form-item>
          <el-form-item label="选择赛事" prop="competitionId">
            <el-select
              v-model="queryParams.competitionId"
              placeholder="请选择"
              clearable
              @keyup.enter.native="handleQuery"
            >
              <el-option
                v-for="item in playList"
                :key="item.id"
                :label="item.name"
                :value="item.id"
              >
              </el-option>
            </el-select>
          </el-form-item>
          <el-form-item>
            <el-button
              type="primary"
              icon="el-icon-search"
              size="mini"
              @click="handleQuery"
              >搜索</el-button
            >
            <el-button icon="el-icon-refresh" size="mini" @click="resetQuery"
              >重置</el-button
            >
          </el-form-item>
        </el-form>

        <el-row :gutter="10" class="mb8">
          <el-col :span="1.5">
            <el-button
              type="primary"
              plain
              icon="el-icon-plus"
              size="mini"
              @click="handleAdd"
              v-hasPermi="['system:shunxu:add']"
              >新增场次</el-button
            >
          </el-col>
          <el-col :span="1.5">
            <el-button
              type="success"
              plain
              icon="el-icon-download"
              size="mini"
              @click="underOrder"
              v-hasPermi="['system:shunxu:edit']"
              >出场顺序模板下载</el-button
            >
          </el-col>
          <el-col :span="1.5">
            <el-button plain icon="el-icon-download" @click="exportAuthe"
              >导出运动员信息表</el-button
            >
          </el-col>
          <el-col :span="1.5">
            <el-button plain icon="el-icon-download" @click="exportOrder"
              >导出出场顺序表</el-button
            >
          </el-col>

          <!-- <el-col :span="1.5">
        <el-button
          type="danger"
          plain
          icon="el-icon-delete"
          size="mini"
          :disabled="multiple"
          @click="handleDelete"
          v-hasPermi="['system:shunxu:remove']"
          >删除</el-button
        >
      </el-col> -->
          <!-- <el-col :span="1.5">
        <el-button
          type="warning"
          plain
          icon="el-icon-download"
          size="mini"
          @click="handleExport"
          v-hasPermi="['system:shunxu:export']"
          >导出</el-button
        >
      </el-col> -->
          <right-toolbar
            :showSearch.sync="showSearch"
            @queryTable="getList"
          ></right-toolbar>
        </el-row>

        <el-table v-loading="loading" :data="shunxuList">
          <!-- <el-table-column type="selection" width="55" align="center" /> -->
          <el-table-column label="场次ID" align="center" prop="id" />
          <el-table-column label="场次信息" align="center" prop="title" />
          <el-table-column label="场次类型" align="center" prop="status">
            <template slot-scope="scope">
              <el-tag :type="scope.row.type == '常规' ? '' : 'warning'">
                {{ scope.row.type }}
              </el-tag>
            </template>
          </el-table-column>
          <!-- <el-table-column label="赛事名称" align="center" prop="game" /> -->
          <el-table-column label="场次状态" align="center" prop="status">
            <template slot-scope="scope">
              <el-dropdown @command="handleClick(scope.row, $event)">
                <el-tag
                  :type="scope.row.status == '进行中' ? 'success' : 'info'"
                >
                  {{ scope.row.status
                  }}<i class="el-icon-edit-outline el-icon--right"></i>
                </el-tag>
                <el-dropdown-menu slot="dropdown">
                  <!-- <el-dropdown-item
                    v-show="scope.row.status !== '未开始'"
                    command="未开始"
                    disabled
                    >未开始</el-dropdown-item
                  > -->
                  <el-dropdown-item
                    v-show="scope.row.status === '未开始'"
                    command="进行中"
                    >进行中</el-dropdown-item
                  >
                  <el-dropdown-item
                    v-show="scope.row.status === '进行中'"
                    command="结束"
                    >结束</el-dropdown-item
                  >
                </el-dropdown-menu>
              </el-dropdown>
            </template>
          </el-table-column>
          <el-table-column
            label="比赛时间"
            align="center"
            prop="startTime"
            width="180"
          >
            <template slot-scope="scope">
              <span>{{ parseTime(scope.row.startTime) }}</span>
            </template>
          </el-table-column>
          <el-table-column
            label="操作"
            align="center"
            class-name="small-padding fixed-width"
            width="300"
          >
            <template slot-scope="scope">
              <el-button
                size="mini"
                type="text"
                icon="el-icon-edit"
                @click="handleUpdate(scope.row)"
                v-hasPermi="['system:shunxu:edit']"
                >修改</el-button
              >
              <el-button
                size="mini"
                type="text"
                 :disabled="
                          scope.row.status === '已结束'"
                @click="refereeSetup(scope.row)"
                v-hasPermi="['system:shunxu:remove']"
                >裁判设置</el-button
              >

              <!-- <el-button
                size="mini"
                type="text"
                @click="exportOrder(scope.row)"
                v-hasPermi="['system:shunxu:remove']"
                >出场顺序下载<i class="el-icon-download"></i
              ></el-button> -->
              <span style="margin-right: 15px">
                <el-upload
                  ref="targetUpload"
                  v-show="scope.row.type === '外部导入'"
                  class="upload-demo"
                  :action="uploadUrl"
                  :on-preview="handlePreview"
                  :on-remove="handleRemove"
                  :before-remove="beforeRemove"
                  :on-success="filesuccess"
                  :on-error="fileError"
                  :headers="headers"
                  :show-file-list="false"
                  :data="paramsData"
                  multiple
                
                >
                  <el-button
                    size="mini"
                    type="text"
                    icon="el-icon-plus"
                    @click="UnderExportOrder(scope.row)"
                    >导入出场顺序</el-button
                  >
                </el-upload>
              </span>
              <el-button
                size="mini"
                type="text"
                @click="handleDelete(scope.row)"
                v-hasPermi="['system:shunxu:remove']"
                >删除</el-button
              >

              <el-button
                size="mini"
                type="text"
                @click="teamexport(scope.row)"
                v-hasPermi="['system:shunxu:remove']"
                >导出排名</el-button
              >
            </template>
          </el-table-column>
        </el-table>

        <pagination
          v-show="total > 0"
          :total="total"
          :page.sync="queryParams.page"
          :limit.sync="queryParams.rowsPerPage"
          @pagination="getList"
        />

        <!-- 添加或修改顺序对话框 -->
        <el-dialog
          :close-on-click-modal="false"
          :title="title"
          :visible.sync="open"
          width="1200px"
          append-to-body
        >
          <el-form ref="form" :model="form" :rules="rules" label-width="80px">
            <el-row>
              <el-col :span="12">
                <el-form-item label="场次信息" prop="title">
                  <el-input v-model="form.title" placeholder="请输入场次信息" />
                </el-form-item>
              </el-col>
              <!-- <el-form-item label="赛事名称" prop="game">
          <el-input v-model="form.game" placeholder="请输入赛事名称" />
        </el-form-item> -->
              <el-col :span="12">
                <el-form-item label="比赛时间" prop="startTime">
                  <el-date-picker
                    v-model="form.startTime"
                    type="datetime"
                    value-format="yyyy-MM-dd HH:mm:ss"
                    placeholder="选择比赛时间"
                  >
                  </el-date-picker>
                </el-form-item>
              </el-col>
            </el-row>
            <el-form-item label="场次类型" prop="type">
              <el-radio-group v-model="form.type">
                <el-radio-button label="常规"></el-radio-button>
                <el-radio-button label="外部导入"></el-radio-button>
              </el-radio-group>
            </el-form-item>
            <el-form-item label="打分公式" prop="formula">
              <el-select v-model="form.formula" placeholder="请选择">
                <el-option
                  v-for="item in formula"
                  :key="item.value"
                  :label="item.label"
                  :value="item.value"
                >
                </el-option>
              </el-select>
            </el-form-item>
            <el-form-item label="比赛项目" prop="applyProjectIds">
              <div class="edit_dev">
                <!-- <el-input v-model="form.groups" placeholder="请输入比赛项目"   clearable
              style="width: 420px" /> -->
                <!-- <el-select
              v-model="value1"
              clearable
              placeholder="请输入比赛项目"
              @change="chooseType"
            >
              <el-option
                v-for="item in projects"
                :key="item.id"
                :label="item.type + '-' + item.name"
                :value="item.type"
              >
              </el-option>
            </el-select>
            <el-select
              v-model="value2"
              clearable
              placeholder="请输入项目组别"
              @change="chooseGroup"
            >
              <el-option
                v-for="item in groups"
                :key="item"
                :label="item"
                :value="item"
              >
              </el-option>
            </el-select>
            <button
              class="transfer-footer"
              slot="right-footer"
              size="small"
              @click.prevent="clearSelect(index)"
            >
              重置
            </button> -->
                <!--  tansfer    style="text-align: left; display: inline-block" -->
                <my-transfer
                  @mouseover.native="addHover"
                  filterable
                  v-model="selectValue"
                  :titles="['选择', '排序']"
                  :props="{
                    key: 'id',
                    label: 'type',
                    label1: 'groups',
                  }"
                  :list1="projects"
                  :list2="groups"
                  :data="applyList"
                  target-order="push"
                  @right-check-change="choose"
                >
                  <span slot-scope="{ option }"
                    >{{ option.label }}
                    <div>
                      <span
                        style="
                          color: #8492a6;
                          font-size: 13px;
                          padding-left: 10px;
                          padding-right: 15px;
                        "
                        >{{ option.projectName }} - {{ option.type }} -
                        {{ option.groups }}- {{ option.createBy }}</span
                      >
                    </div>
                    <div
                      style="
                        color: #8492a6;
                        font-size: 13px;
                        padding-left: 10px;
                      "
                    >
                      运动员：
                      <span v-for="item in option.athletes" :key="item.id">
                        {{ item.name }}
                      </span>
                    </div>
                  </span>
                  <el-button
                    class="transfer-footer"
                    slot="right-footer"
                    size="small"
                    @click="handleUp(index)"
                    >上移</el-button
                  >
                  <el-button
                    class="transfer-footer"
                    slot="right-footer"
                    size="small"
                    @click="handleDown(index)"
                    >下移</el-button
                  >
                </my-transfer>
              </div>
            </el-form-item>
          </el-form>
          <div slot="footer" class="dialog-footer">
            <el-button type="primary" @click="submitForm">确 定</el-button>
            <el-button @click="cancel">取 消</el-button>
          </div>
        </el-dialog>

        <!-- 添加执法裁判 -->
        <el-dialog
          :close-on-click-modal="false"
          :title="titleReffer"
          :visible.sync="openReffer"
          width="1000px"
          append-to-body
        >
          <el-form
            :model="dynamicValidateForm"
            ref="dynamicValidateForm"
            label-width="100px"
            class="demo-dynamic"
          >
            <el-row>
              <el-col :span="8">
                <el-form-item
                  label="裁判长: 姓名"
                  :prop="dynamicValidateForm.refferJudge.name"
                  label-width="150px"
                  :rules="[
                    {
                      required: true,
                      message: '姓名不能为空',
                      trigger: 'blur',
                    },
                  ]"
                >
                  <el-input
                    v-model="dynamicValidateForm.refferJudge.name"
                    placeholder="请输入姓名"
                  />
                </el-form-item>
              </el-col>
              <el-col :span="8">
                <el-form-item
                  label="身份证号"
                  :prop="dynamicValidateForm.refferJudge.idCard"
                  :rules="[
                    {
                      required: true,
                      message: '请输入身份证号',
                      trigger: 'blur',
                    },
                  ]"
                >
                  <el-input
                    v-model="dynamicValidateForm.refferJudge.idCard"
                    placeholder="身份证号"
                  >
                  </el-input>
                </el-form-item>
              </el-col>
            </el-row>

            <el-row
              v-for="(domain, index) in dynamicValidateForm.deputyReferees"
              :key="'tilte' + index"
            >
              <el-col :span="6">
                <el-form-item
                  :prop="'deputyReferees.' + index + '.name'"
                  :label="'副裁判' + (index + 1) + ': 姓名'"
                  label-width="150px"
                  :rules="{
                    required: true,
                    message: '姓名不能为空',
                    trigger: 'blur',
                  }"
                >
                  <el-input v-model="domain.name"></el-input>
                </el-form-item>
              </el-col>
              <el-col :span="8">
                <el-form-item
                  label="身份证号"
                  :prop="'deputyReferees.' + index + '.idCard'"
                  :rules="[
                    {
                      required: true,
                      message: '身份证号不能为空',
                      trigger: 'blur',
                    },
                    {
                      validator: checkIdNumData,
                      trigger: 'blur',
                    },
                  ]"
                >
                  <el-input v-model="domain.idCard"></el-input>
                </el-form-item>
              </el-col>
              <!-- <el-col :span="6">
                <el-form-item
                  label="裁判类型"
                  :prop="'deputyReferees.' + index + '.type'"
                  :rules="[
                    { required: true, message: '裁判类型', trigger: 'blur' },
                  ]"
                >
                
                  <el-select v-model="domain.type" placeholder="请选择裁判类型">
                    <el-option
                      v-for="item in options"
                      :key="item.value"
                      :label="item.label"
                      :value="item.value"
                    >
                    </el-option>
                  </el-select>
                </el-form-item>
              </el-col> -->
              <el-button
                style="margin-left: 30px"
                @click.prevent="removeDeputyReferee(index)"
                >删除</el-button
              >
            </el-row>
            <el-form-item>
              <el-button style="margin-left: 50px" @click="addDeputyReferee"
                >新增副裁判长</el-button
              >
            </el-form-item>
            <!-- <el-row>
              <el-col :span="8">
                <el-form-item
                  label="副裁判长: 姓名"
                  :prop="dynamicValidateForm.deputyReferee.name"
                  label-width="150px"
                  :rules="[
                    {
                      required: true,
                      message: '姓名不能为空',
                      trigger: 'blur',
                    },
                  ]"
                >
                  <el-input
                    v-model="dynamicValidateForm.deputyReferee.name"
                    placeholder="请输入姓名"
                  />
                </el-form-item>
              </el-col>
              <el-col :span="8">
                <el-form-item
                  label="身份证号"
                  :prop="dynamicValidateForm.deputyReferee.idCard"
                  :rules="[
                    {
                      required: true,
                      message: '请输入身份证号',
                      trigger: 'blur',
                    },
                  ]"
                >
                  <el-input
                    v-model="dynamicValidateForm.deputyReferee.idCard"
                    placeholder="身份证号"
                  >
                  </el-input>
                </el-form-item>
              </el-col>
            </el-row> -->
            <el-divider><i>普通裁判</i></el-divider>
            <el-row
              v-for="(domain, index) in dynamicValidateForm.artisticJudges"
              :key="index"
            >
              <el-col :span="6">
                <el-form-item
                  :prop="'artisticJudges.' + index + '.name'"
                  :label="'裁判' + (index + 1) + ': 姓名'"
                  label-width="150px"
                  :rules="{
                    required: true,
                    message: '姓名不能为空',
                    trigger: 'blur',
                  }"
                >
                  <el-input v-model="domain.name"></el-input>
                </el-form-item>
              </el-col>
              <el-col :span="8">
                <el-form-item
                  label="身份证号"
                  :prop="'artisticJudges.' + index + '.idCard'"
                  :rules="[
                    {
                      required: true,
                      message: '身份证号不能为空',
                      trigger: 'blur',
                    },
                    {
                      validator: checkIdNumData,
                      trigger: 'blur',
                    },
                  ]"
                >
                  <el-input v-model="domain.idCard"></el-input>
                </el-form-item>
              </el-col>
              <el-col :span="6">
                <el-form-item
                  label="裁判类型"
                  :prop="'artisticJudges.' + index + '.type'"
                  :rules="[
                    { required: true, message: '裁判类型', trigger: 'blur' },
                  ]"
                >
                  <!-- <el-input v-model="domain.type"></el-input> -->
                  <el-select v-model="domain.type" placeholder="请选择裁判类型">
                    <el-option
                      v-for="item in options"
                      :key="item.value"
                      :label="item.label"
                      :value="item.value"
                    >
                    </el-option>
                  </el-select>
                </el-form-item>
              </el-col>
              <el-button
                style="margin-left: 30px"
                @click.prevent="removeDomain(index)"
                >删除</el-button
              >
            </el-row>

            <el-form-item>
              <!-- <el-button
            type="primary"
            @click="submitFormReffer('dynamicValidateForm')"
            >提交</el-button
          > -->
              <el-button style="margin-left: 50px" @click="addDomain"
                >新增裁判</el-button
              >
              <!-- <el-button @click="resetFormReffer('dynamicValidateForm')"
            >重置所有</el-button
          > -->
            </el-form-item>
          </el-form>
          <div slot="footer" class="dialog-footer">
            <!-- <el-button type="primary" @click="submitForm">确 定</el-button> -->
            <el-button
              type="primary"
              @click="submitFormReffer('dynamicValidateForm')"
              >提交</el-button
            >
            <el-button @click="cancelReffer">取 消</el-button>
          </div>
        </el-dialog>
      </el-tab-pane>
      <el-tab-pane label="正在进行">
        <el-form
          :model="queryGoingParams"
          ref="queryForm"
          size="small"
          :inline="true"
          v-show="showSearch"
          label-width="68px"
        >
          <el-form-item label="场次信息" prop="title">
            <el-input
              v-model="queryGoingParams.title"
              placeholder="请输入场次信息"
              clearable
              @keyup.enter.native="handleQuery"
            />
          </el-form-item>
          <el-form-item label="选择赛事" prop="competitionId">
            <el-select
              v-model="queryGoingParams.competitionId"
              placeholder="请选择"
              clearable
              @keyup.enter.native="handleQuery"
            >
              <el-option
                v-for="item in playList"
                :key="item.id"
                :label="item.name"
                :value="item.id"
              >
              </el-option>
            </el-select>
          </el-form-item>
          <el-form-item>
            <el-button
              type="primary"
              icon="el-icon-search"
              size="mini"
              @click="handleGoingQuery"
              >搜索</el-button
            >
            <el-button
              icon="el-icon-refresh"
              size="mini"
              @click="resetGoingQuery"
              >重置</el-button
            >
          </el-form-item>
        </el-form>
        <!-- 
        <el-row :gutter="10" class="mb8">
          <el-col :span="1.5">
            <el-button
              type="primary"
              plain
              icon="el-icon-plus"
              size="mini"
              @click="handleAdd"
              v-hasPermi="['system:shunxu:add']"
              >新增场次</el-button
            >
          </el-col> -->
        <!-- <el-col :span="1.5">
        <el-button
          type="success"
          plain
          icon="el-icon-edit"
          size="mini"
          :disabled="single"
          @click="handleUpdate"
          v-hasPermi="['system:shunxu:edit']"
          >修改</el-button
        >
      </el-col> -->
        <!-- <el-col :span="1.5">
        <el-button
          type="danger"
          plain
          icon="el-icon-delete"
          size="mini"
          :disabled="multiple"
          @click="handleDelete"
          v-hasPermi="['system:shunxu:remove']"
          >删除</el-button
        >
      </el-col> -->
        <!-- <el-col :span="1.5">
        <el-button
          type="warning"
          plain
          icon="el-icon-download"
          size="mini"
          @click="handleExport"
          v-hasPermi="['system:shunxu:export']"
          >导出</el-button
        >
      </el-col> -->
        <!-- <right-toolbar
            :showSearch.sync="showSearch"
            @queryTable="getList"
          ></right-toolbar>
        </el-row> -->

        <el-table
          v-loading="loading"
          :data="goingList"
          @selection-change="handleSelectionChange"
        >
          <el-table-column type="selection" width="55" align="center" />
          <el-table-column label="场次ID" align="center" prop="id" />
          <el-table-column label="场次信息" align="center" prop="title" />
          <!-- <el-table-column label="赛事名称" align="center" prop="game" /> -->
          <el-table-column label="场次状态" align="center" prop="status">
            <template slot-scope="scope">
              <el-dropdown @command="handleClick(scope.row, $event)">
                <el-tag
                  :type="scope.row.status == '进行中' ? 'success' : 'info'"
                >
                  {{ scope.row.status
                  }}<i class="el-icon-edit-outline el-icon--right"></i>
                </el-tag>
                <el-dropdown-menu slot="dropdown">
                  <el-dropdown-item
                    v-show="scope.row.status === '未开始'"
                    command="未开始"
                    disabled
                    >未开始</el-dropdown-item
                  >
                  <el-dropdown-item
                    v-show="scope.row.status === '未开始'"
                    command="进行中"
                    >进行中</el-dropdown-item
                  >
                  <el-dropdown-item
                    v-show="scope.row.status === '进行中' "
                    command="结束"
                    >结束</el-dropdown-item
                  >
                </el-dropdown-menu>
              </el-dropdown>
            </template>
          </el-table-column>
          <el-table-column
            label="比赛时间"
            align="center"
            prop="startTime"
            width="180"
          >
            <template slot-scope="scope">
              <span>{{ parseTime(scope.row.startTime) }}</span>
            </template>
          </el-table-column>
          <el-table-column
            label="操作"
            align="center"
            class-name="small-padding fixed-width"
          >
            <template slot-scope="scope">
              <el-button
                size="mini"
                type="text"
                icon="el-icon-edit"
                @click="score(scope.row)"
                v-hasPermi="['system:shunxu:edit']"
                >评分</el-button
              >

              <el-button
                size="mini"
                type="text"
                @click="teamSort(scope.row)"
                v-hasPermi="['system:shunxu:remove']"
                >排名</el-button
              >

              <el-button
                size="mini"
                type="text"
                @click="teamexport(scope.row)"
                v-hasPermi="['system:shunxu:remove']"
                >导出排名</el-button
              >
            </template>
          </el-table-column>
        </el-table>

        <pagination
          v-show="total2 > 0"
          :total="total2"
          :page.sync="queryGoingParams.page"
          :limit.sync="queryGoingParams.rowsPerPage"
          @pagination="getListGoing"
        />
        <!-- 导出 -->
        <!-- <el-dialog
          title="导出排名"
          :visible.sync="centerDialogVisible"
          width="30%"
          center
        >
          <el-form :model="exportForm">
            <el-form-item label="项目" :label-width="formLabelWidth">
              <el-select v-model="exportForm.projectId" placeholder="请选择">
                <el-option
                  v-for="item in projectList"
                  :key="item.id"
                  :label="item.name"
                  :value="item.id"
                >
                </el-option>
              </el-select>
            </el-form-item>
            <el-form-item label="分类" :label-width="formLabelWidth">
              <el-select v-model="exportForm.type" placeholder="请选择项目分类">
                <el-option
                  v-for="item in typeDic"
                  :key="item"
                  :label="item"
                  :value="item"
                >
                </el-option>
              </el-select>
            </el-form-item>
            <el-form-item label="组别" :label-width="formLabelWidth">
              <el-select
                v-model="exportForm.group"
                placeholder="请选择活动组别"
              >
                <el-option
                  v-for="item in TypeGroups"
                  :key="item"
                  :label="item"
                  :value="item"
                >
                </el-option>
              </el-select>
            </el-form-item>
          </el-form>
          <span slot="footer" class="dialog-footer">
            <el-button @click="centerDialogVisible = false">取 消</el-button>
            <el-button type="primary" @click="exportEvery">导 出</el-button>
          </span>
        </el-dialog> -->

        <!-- 评分 -->
        <el-dialog
          :close-on-click-modal="false"
          :visible.sync="openScore"
          :fullscreen="true"
          width="1000px"
          append-to-body
          @closed="closedScore"
        >
          <div class="titleName">
            <i>{{ competitionName + " " + orderName }}</i>
          </div>
          <div class="">
            <el-row>
              <el-col>
                <el-table
                  ref="gameTable"
                  :data="tableData"
                  highlight-current-row
                  height="300"
                  style="width: 100%"
                  @row-click="rowScore"
                >
                  <el-table-column prop="sort" label="顺序" width="50">
                    <template slot-scope="scope">
                      {{ scope.$index + 1 }}
                    </template></el-table-column
                  >
                  <el-table-column
                    :show-overflow-tooltip="true"
                    prop="project"
                    label="项目"
                  >
                    <template slot-scope="scope">
                      {{
                        scope.row.type +
                        "-" +
                        scope.row.projectName +
                        "-" +
                        scope.row.groups
                      }}
                    </template>
                  </el-table-column>
                  <el-table-column
                    :show-overflow-tooltip="true"
                    prop="teamName"
                    label="队伍"
                  ></el-table-column>
                  <el-table-column
                    :show-overflow-tooltip="true"
                    prop="teamName"
                    label="运动员"
                    ><template slot-scope="scope">
                      <span
                        v-for="tag in scope.row.athletes"
                        :key="tag.index"
                        type="info"
                        size="small"
                      >
                        <el-tag type="info">
                          {{ tag.name }}
                        </el-tag>
                      </span>
                    </template>
                  </el-table-column>

                  <el-table-column prop="score" label="分数"></el-table-column>

                  <el-table-column prop="status" label="状态" width="100">
                    <template slot-scope="scope">
                      <el-tag
                        :type="
                          scope.row.status === '已打分' ? 'success' : 'primary'
                        "
                        disable-transitions
                        >{{ scope.row.status }}</el-tag
                      >
                    </template>
                  </el-table-column>
                  <el-table-column label="操作">
                    <template slot-scope="scope">
                      <el-button
                        size="mini"
                        type="success"
                        @click="reStart(scope.$index, scope.row)"
                        v-show="
                          scope.row.status === '打分结束' ||
                          scope.row.status === '正在打分'
                        "
                        :disabled="scope.row.status === '正在打分'"
                        >重新打分</el-button
                      >
                      <el-button
                        size="mini"
                        type="success"
                        @click="handleStart(scope.$index, scope.row)"
                        v-show="scope.row.status === '未打分'"
                        >开始</el-button
                      >
                      <el-button
                        size="mini"
                        type="danger"
                        @click="handleStop(scope.$index, scope.row)"
                        :disabled="
                          scope.row.status === '打分结束' ||
                          scope.row.status === '弃权'
                        "
                        >结束</el-button
                      >
                      <el-button
                        size="mini"
                        type="warning"
                        @click="handleGiveUp(scope.$index, scope.row)"
                        :disabled="
                          scope.row.status === '弃权' ||
                          scope.row.status === '打分结束'
                        "
                        >弃权</el-button
                      >
                    </template>
                  </el-table-column>
                </el-table>
              </el-col>
            </el-row>
            <div class="titleName2">
              <i>{{ RefferScoreTitle }} (分数)</i>
            </div>
            <!-- <div v-show="!ScoreInfo">暂未评分</div> -->
            <el-card shadow="never" style="margin: 20px 0">
              <el-row :gutter="10" class="panel-group">
                <el-col
                  :xs="12"
                  :sm="8"
                  :md="4"
                  :lg="{ span: '24-5' }"
                  class="card-panel-col"
                  v-for="item in ScoreInfo"
                  :key="item.id"
                  style="margin-bottom: 20px"
                >
                  <el-card shadow="never" :body-style="{ padding: '0px' }">
                    <div style="padding-top: 14px">
                      <div class="" style="text-align: center">
                        <div class="">{{ item.type }}({{ item.name }})</div>
                        <div
                          class=""
                          style="font-size: 30px; padding-top: 10px"
                        >
                          {{ item.score }}
                        </div>
                      </div>
                      <div
                        class="bottom clearfix"
                        :class="[index % 2 == 0 ? 'already' : 'noready']"
                      >
                        <el-row type="flex" justify="space-around">
                          <!-- <el-col v-if="index % 2 == 0">
                            <i class="el-icon-refresh">重打</i>
                          </el-col>
                          <el-col v-if="index % 2 == 0">
                            <i class="el-icon-bottom">下线</i>
                          </el-col> -->
                          <el-col>
                            <!-- <i class="el-icon-edit" @click="editScore(item)"
                              >编辑</i
                            > -->
                          </el-col>
                        </el-row>
                      </div>
                    </div>
                  </el-card>
                </el-col>
              </el-row>

              <el-row :gutter="10" class="panel-group" type="flex">
                <el-col
                  :xs="12"
                  :sm="8"
                  :lg="{ span: '24-5' }"
                  class="card-panel-col"
                >
                  <el-card shadow="never" :body-style="{ padding: '0px' }">
                    <div style="padding-top: 14px">
                      <div class="" style="text-align: center">
                        <div class="">主裁加分</div>
                        <div
                          class=""
                          style="font-size: 30px; padding-top: 10px"
                        >
                          {{ form3.addScore }}
                        </div>
                      </div>
                      <div class="bottom clearfix headreferee">
                        <i class="el-icon-edit" @click="openJajian(1)">编辑</i>
                      </div>
                    </div>
                  </el-card>
                </el-col>
                <el-col
                  :xs="12"
                  :sm="8"
                  :lg="{ span: '24-5' }"
                  class="card-panel-col"
                >
                  <el-card shadow="never" :body-style="{ padding: '0px' }">
                    <div style="padding-top: 14px">
                      <div class="" style="text-align: center">
                        <div class="">主裁减分</div>
                        <div
                          class=""
                          style="font-size: 30px; padding-top: 10px"
                        >
                          {{ form3.reduceScore }}
                        </div>
                      </div>
                      <div class="bottom clearfix headreferee">
                        <i class="el-icon-edit" @click="openJajian(0)">编辑</i>
                      </div>
                    </div>
                  </el-card>
                </el-col>

                <el-col
                  :xs="12"
                  :sm="8"
                  :lg="{ span: '24-5' }"
                  class="card-panel-col"
                >
                  <el-card shadow="never" :body-style="{ padding: '0px' }">
                    <div style="padding-top: 14px">
                      <div class="" style="text-align: center">
                        <div class="">总得分</div>
                        <div
                          class=""
                          style="font-size: 60px; padding-top: 10px"
                        >
                          {{ form3.averageScore }}
                        </div>
                      </div>
                      <!-- <div class="bottom clearfix headreferee">
                    
                      </div> -->
                    </div>
                  </el-card>
                </el-col>
                <el-col
                  :xs="12"
                  :sm="8"
                  :lg="{ span: '24-15' }"
                  class="card-panel-col"
                >
                  <el-card shadow="never" :body-style="{ padding: '0px' }">
                    <!-- <el-button @click="positionIndex('3')">定位</el-button> -->
                    <el-row type="flex">
                      <el-col>
                        <div style="padding-top: 14px">
                          <div class="" style="text-align: center">
                            <div class="">最终得分</div>
                            <div
                              class=""
                              style="font-size: 60px; padding-top: 10px"
                            >
                              {{ sumNum }}
                            </div>
                          </div>
                        </div>
                      </el-col>
                      <el-col>
                        <!-- <div style="padding-top: 14px">
                          <div class="" style="text-align: center">
                            <div class="">排名</div>
                            <div
                              class=""
                              style="font-size: 80px; padding-top: 10px"
                            >
                              1
                            </div>
                          </div>
                        </div> -->
                        <div class="submit-score">
                          <el-button
                            icon="el-icon-upload2"
                            type="success"
                            @click="submitRefferJudge"
                            >提交打分</el-button
                          >
                        </div>
                      </el-col>
                      <el-col>
                        <div class="submit-score">
                          <el-button
                            icon="el-icon-upload2"
                            type="info"
                            @click="looksort"
                            >查看排名</el-button
                          >
                        </div>
                      </el-col>
                    </el-row>
                  </el-card>
                </el-col>
              </el-row>
            </el-card>
          </div>
        </el-dialog>

        <!-- 排名  -->
        <el-dialog
          :close-on-click-modal="false"
          :visible.sync="openSort"
          :fullscreen="true"
          width="1000px"
          append-to-body
        >
          <div class="titleName">
            <i>{{ competitionSortName + " " + orderSortName }}</i>
          </div>
          <div class="">
            <el-row>
              <el-col>
                <el-table
                  ref="gameTable"
                  :data="scoreSortList"
                  highlight-current-row
                  height="300"
                  style="width: 100%"
                >
                  <el-table-column prop="sort" label="排名" width="80">
                    <template slot-scope="scope">
                      {{ scope.$index + 1 }}
                    </template></el-table-column
                  >
                  <el-table-column
                    :show-overflow-tooltip="true"
                    prop="project"
                    label="项目"
                    width="600"
                  >
                    <template slot-scope="scope">
                      {{
                        scope.row.type +
                        "-" +
                        scope.row.projectName +
                        "-" +
                        scope.row.groups
                      }}
                    </template>
                  </el-table-column>
                  <el-table-column
                    :show-overflow-tooltip="true"
                    prop="teamName"
                    label="队伍"
                    width="400"
                  ></el-table-column>
                  <el-table-column
                    :show-overflow-tooltip="true"
                    prop="teamName"
                    label="运动员"
                    ><template slot-scope="scope">
                      <span
                        v-for="tag in scope.row.athletes"
                        :key="tag.index"
                        type="info"
                        size="small"
                      >
                        <el-tag type="info">
                          {{ tag.name }}
                        </el-tag>
                      </span>
                    </template>
                  </el-table-column>

                  <el-table-column prop="score" label="分数">
                    <template slot-scope="scope">
                      <el-tag type="success">
                        {{ scope.row.score }}
                      </el-tag>
                    </template></el-table-column
                  >

                  <!-- <el-table-column prop="status" label="状态" width="100">
                    <template slot-scope="scope">
                     <el-button plain icon="el-icon-download" @click="exportAuthe(scope.row)" >导出排名</el-button >
                    </template>
                  </el-table-column> -->
                </el-table>
              </el-col>
            </el-row>
          </div>
        </el-dialog>

        <!-- 修改分数 -->
        <el-dialog
          :close-on-click-modal="false"
          title="分数修改"
          :visible.sync="dialogFormVisible"
        >
          <el-form ref="formScore" :model="formScore" :rules="rules">
            <el-form-item label="分数" prop="score">
              <el-input v-model="formScore.score" autocomplete="off"></el-input>
            </el-form-item>
          </el-form>
          <div slot="footer" class="dialog-footer">
            <el-button @click="dialogFormVisible = false">取 消</el-button>
            <el-button type="primary" @click="submitRefferScore"
              >确 定</el-button
            >
          </div>
        </el-dialog>

        <el-dialog
          :close-on-click-modal="false"
          title="分数修改"
          :visible.sync="dialogFormVisible2"
          :show-close="false"
        >
          <el-form ref="form3" :model="form3" :rules="rules">
            <el-form-item v-show="jia" label="分数" prop="addScore">
              <el-input v-model="form3.addScore"></el-input>
            </el-form-item>
            <el-form-item v-show="jian" label="分数" prop="reduceScore">
              <el-input v-model="form3.reduceScore"></el-input>
            </el-form-item>
          </el-form>
          <div slot="footer" class="dialog-footer">
            <el-button @click="cancelQuXiao">取 消</el-button>
            <el-button type="primary" @click="queding">确 定</el-button>
          </div>
        </el-dialog>
      </el-tab-pane>
      <!-- <el-tab-pane label="角色管理">角色管理</el-tab-pane>
      <el-tab-pane label="定时任务补偿">定时任务补偿</el-tab-pane> -->
    </el-tabs>

    <el-dialog
      :close-on-click-modal="false"
      title="导出排名"
      :visible.sync="centerDialogVisible"
      width="30%"
      center
    >
      <el-form ref="exportForm" :model="exportForm" :rules="exportRules">
        <el-form-item
          label="项目"
          :label-width="formLabelWidth"
          prop="projectId"
        >
          <el-select v-model="exportForm.projectId" filterable placeholder="请选择">
            <el-option
              v-for="item in projectList"
              :key="item.id"
              :label="item.name"
              :value="item.id"
            >
            </el-option>
          </el-select>
        </el-form-item>
        <el-form-item label="分类" :label-width="formLabelWidth" prop="type">
          <el-select v-model="exportForm.type" filterable placeholder="请选择项目分类">
            <el-option
              v-for="item in typeDic"
              :key="item"
              :label="item"
              :value="item"
            >
            </el-option>
          </el-select>
        </el-form-item>
        <el-form-item label="组别" :label-width="formLabelWidth" prop="group">
          <el-select v-model="exportForm.group" filterable placeholder="请选择活动组别">
            <el-option
              v-for="item in TypeGroups"
              :key="item"
              :label="item"
              :value="item"
            >
            </el-option>
          </el-select>
        </el-form-item>
      </el-form>
      <span slot="footer" class="dialog-footer">
        <el-button @click="centerDialogVisible = false">取 消</el-button>
        <el-button type="primary" @click="exportEvery">导 出</el-button>
      </span>
    </el-dialog>
  </div>
</template>

<script>
import {
  listShunxu,
  getShunxu,
  delShunxu,
  addShunxu,
  updateShunxu,
  getplay,
  getApplys,
  setReffer,
  getOrderReffers,
  startOrder,
  endOrder,
  startScore,
  endScore,
  abstention,
  refferScore,
  submitScore,
  underOrder,
  gameSort,
  reStartScore,
} from "@/api/game/order";
import { listplay } from "@/api/game/apply";
import myTransfer from "../../../components/transfer/index.vue";
import { getToken } from "@/utils/auth";
import { getGroupsDic } from "@/api/game/play";
import { listProject, getTypeDic } from "@/api/game/project";
export default {
  name: "Shunxu",
  components: {
    myTransfer,
  },
  data() {
    // 身份证号校验
    var checkIdNum = (rule, value, callback) => {
      const reg =
        /(^[1-9]\d{7}((0\d)|(1[0-2]))(([0|1|2]\d)|3[0-1])\d{3}$)|(^[1-9]\d{5}(18|19|20)\d{2}((0[1-9])|(1[0-2]))(([0-2][1-9])|10|20|30|31)\d{3}[0-9Xx]$)/;
      if (!value) {
        return callback(new Error("证件号码不能为空"));
      } else if (!reg.test(value)) {
        return callback(new Error("证件号码不正确"));
      } else {
        callback();
      }
    };
    return {
      fileList: [],
      headers: {
        Authorization: "Bearer " + getToken(),
      },
      paramsData: {},
      BaseUrl: process.env.VUE_APP_BASE_API,
      uploadUrl:
        process.env.VUE_APP_BASE_API + "/work/competition/importOrderSort", // 上传
      checkIdNumData: checkIdNum,
      dialogFormVisible2: false,
      //项目打分情况
      ScoreInfo: [],
      // 打分
      form: {
        value: null,
      },
      formScore: {
        score: 0,
      },
      //已经排序信息
      finishOrder: [],
      // 场次id
      orderId: "",
      dialogFormVisible: false,
      tableData: [],
      options: [],
      formula: [
        {
          value: "健身操舞",
          label: "健身操舞",
        },
        {
          value: "舞蹈啦啦操",
          label: "舞蹈啦啦操",
        },
        {
          value: "技巧啦啦操",
          label: "技巧啦啦操",
        },
        {
          value: "竞技健美操2.0",
          label: "竞技健美操2.0",
        },
        {
          value: "竞技健美操1.8",
          label: "竞技健美操1.8",
        },
        {
          value: "竞技健美操1.7",
          label: "竞技健美操1.7",
        },
      ],
      dynamicValidateForm: {
        orderId: "",
        artisticJudges: [
          {
            name: "",
            idCard: "",
            type: "",
          },
        ],
        deputyReferees: [
          {
            name: "",
            idCard: "",
            type: "副裁判长",
          },
        ],
        refferJudge: {
          name: "",
          idCard: "",
          type: "裁判长",
        },
      },
      filterMethod(query, item) {
        return item.type.indexOf(query) > -1 || item.groups.indexOf(query) > -1;
      },
      nowCompetitionId: "",
      //比赛名称
      competitionName: "",
      //场次名称
      orderName: "",
      projectId: "",
      group: "",
      value1: "",
      value2: "",
      selectValue: [],
      //右侧列表排序
      sort: "",
      //右侧列表被选中内容
      item: "",
      // 右侧列表被选中下标值
      index: "",
      //报名信息
      applyList: [],
      groups: [],
      // 比赛项目
      projects: [],
      // 比赛列表
      playList: [],
      // 遮罩层
      loading: true,
      // 选中数组
      ids: [],
      // 非单个禁用
      single: true,
      // 非多个禁用
      multiple: true,
      // 显示搜索条件
      showSearch: true,
      // 总条数
      total: 0,
      total2: 0,
      exportForm: {},
      formLabelWidth: "120px",
      // 顺序表格数据
      shunxuList: [],
      // 正在进行场次数据
      goingList: [],
      form3: {},

      // 弹出层标题
      title: "",
      titleReffer: "",
      titleScore: "",
      // 是否显示弹出层
      open: false,
      openReffer: false,
      openScore: false,
      // 查询参数
      queryParams: {
        page: 1,
        rowsPerPage: 10,
        info: null,
        game: null,
        status: null,
        time: null,
      },
      formRefferInfo: {},
      queryGoingParams: {
        page: 1,
        rowsPerPage: 10,
        competitionId: null,
        game: null,
        status: null,
        time: null,
      },
      RefferScoreTitle: "",
      openSort: false,
      sortScore: [],
      scoreSortList: [],
      jia: false,
      jian: false,
      nowfenshu: 0,
      orderSortName: "",
      competitionSortName: "",
      rowFormula: "",
      // 表单参数
      //当前行
      nowRowid: "",
      form: {},
      formReffer: {},
      centerDialogVisible: false,
      typeDic: [],
      TypeGroups: [],
      projectList: [],
      // 表单校验
      exportRules: {
        projectId: [
          { required: true, message: "场次不能为空", trigger: "blur" },
        ],
        group: [{ required: true, message: "分组不能为空", trigger: "blur" }],
        type: [
          { required: true, message: "比赛大类不能为空", trigger: "blur" },
        ],
      },
      rules: {
        info: [
          { required: true, message: "场次信息不能为空", trigger: "blur" },
        ],
        title: [
          { required: true, message: "场次标题不能为空", trigger: "blur" },
        ],
        formula: [
          { required: true, message: "打分公式不能为空", trigger: "blur" },
        ],
        addScore: [
          {
            pattern:
              /(^[1-9]([0-9]+)?(\.[0-9]{1,2})?$)|(^(0){1}$)|(^[0-9]\.[0-9]([0-9])?$)/,
            message: "必须为数字，且最多两位小数！",
            trigger: "blur",
          },
        ],
        reduceScore: [
          {
            pattern:
              /(^[1-9]([0-9]+)?(\.[0-9]{1,2})?$)|(^(0){1}$)|(^[0-9]\.[0-9]([0-9])?$)/,
            message: "必须为数字，且最多两位小数！",
            trigger: "blur",
          },
        ],
        score: [
          {
            pattern:
              /(^[1-9]([0-9]+)?(\.[0-9]{1,2})?$)|(^(0){1}$)|(^[0-9]\.[0-9]([0-9])?$)/,
            message: "必须为数字，且最多两位小数！",
            trigger: "blur",
          },
        ],
      },

      //定时器
      timerReffer: {},
      //主裁得分
      mainReffer: {},
    };
  },
  created() {
    this.getList();
    this.getPlayList();
    this.getListGoing();
  },
  computed: {
    sumNum: function () {
      return (
        parseFloat(this.form3.addScore ? this.form3.addScore : 0) +
        parseFloat(this.form3.averageScore ? this.form3.averageScore : 0) -
        parseFloat(this.form3.reduceScore ? this.form3.reduceScore : 0)
      ).toFixed(2);
    },
  },
  beforeDestroy() {
    //页面关闭时清除定时器
    if (this.timerReffer) {
      clearInterval(this.timerReffer);
    }
  },
  methods: {
    addHover(e) {
      const target = e.target;
      if (target.title) return;
      target.title = target.innerText;
    },
    looksort() {
      gameSort(this.orderId).then((res) => {
        this.scoreSortList = res.data;
      });
      this.openSort = true;
      getShunxu(this.orderId).then((res) => {
        this.orderSortName = res.data.title;
        //获取比赛名称
        getplay(res.data.competitionId).then((res) => {
          this.competitionSortName = res.data.name;
        });
      });
    },

    // 导出
    exportEvery() {
      this.$refs["exportForm"].validate((valid) => {
        if (valid) {
          if (this.rowFormula === "健身操舞") {
            this.downloadFile(
              "/work/scoreExport/teamScoreJianShenCao",
              {
                competitionId: this.exportForm.competitionId,
                projectId: this.exportForm.projectId,
                group: this.exportForm.group,
                type: this.exportForm.type,
              },
              `排名_${
                new Date().getFullYear() +
                "-" +
                (new Date().getMonth() + 1) +
                "-" +
                new Date().getDate()
              }.xlsx`
            );
          } else if (this.rowFormula.includes("竞技健美操")) {
            this.downloadFile(
              "/work/scoreExport/teamScoreJingji",
              {
                competitionId: this.exportForm.competitionId,
                projectId: this.exportForm.projectId,
                group: this.exportForm.group,
                type: this.exportForm.type,
              },
              `排名_${
                new Date().getFullYear() +
                "-" +
                (new Date().getMonth() + 1) +
                "-" +
                new Date().getDate()
              }.xlsx`
            );
          } else {
            this.downloadFile(
              "/work/scoreExport/teamScorelalaCao",
              {
                competitionId: this.exportForm.competitionId,
                projectId: this.exportForm.projectId,
                group: this.exportForm.group,
                type: this.exportForm.type,
              },
              `排名_${
                new Date().getFullYear() +
                "-" +
                (new Date().getMonth() + 1) +
                "-" +
                new Date().getDate()
              }.xlsx`
            );
          }
          this.centerDialogVisible = false;
        }
      });
    },

    // 导出排名
    teamexport(row) {
      this.resetExport();

      this.rowFormula = row.formula;
      getTypeDic().then((res) => {
        this.typeDic = res.data;
        console.log("-->"+this.typeDic)
      });
      getGroupsDic().then((res) => {
        this.TypeGroups = res.data; 
        console.log("------->"+this.TypeGroups)
      });

      listProject(row.competitionId).then((response) => {
        this.projectList = response.data;
      });
      this.exportForm.competitionId = row.competitionId;

      this.centerDialogVisible = true;
    },

    resetExport() {
      this.exportForm = {
        competitionId: null,
        projectId: null,
        type: null,
        group: null,
      };
      this.resetForm("exportForm");
    },

    teamSort(row) {
      gameSort(row.id).then((res) => {
        this.scoreSortList = res.data;
      });
      this.openSort = true;
      getShunxu(row.id).then((res) => {
        this.orderSortName = res.data.title;
        //获取比赛名称
        getplay(res.data.competitionId).then((res) => {
          this.competitionSortName = res.data.name;
        });
      });
    },

    // changeRed({ row }) {
    //   if (row.status == "正在打分") {
    //     return {
    //       background: "#F4C5B9",
    //     };
    //   }
    // },
    UnderExportOrder(row) {
      let params = { orderId: row.id };
      this.paramsData = params;
    },
    // 上传
    filesuccess(res, file) {
      this.$refs.targetUpload.clearFiles()
      this.getList();
      console.log("上传成功a");
      if (res.code === 200) {
        this.$message({
          message: "导入出场顺序成功",
          type: "success",
          duration: 1500,
        });
      } else {
        this.$modal.msgError(res.msg);
      }
       
    },
      fileError(res, file) {
         this.$refs.targetUpload.clearFiles()
        this.getList();
        this.$modal.msgError(res.msg);
    },
    // 文件上传
    handleRemove(file, fileList) {
      console.log(file, fileList);
    },
    handlePreview(file) {
      console.log(file);
    },
    handleExceed(files, fileList) {
      this.$message.warning(
        `当前限制选择 3 个文件，本次选择了 ${files.length} 个文件，共选择了 ${
          files.length + fileList.length
        } 个文件`
      );
    },
    beforeRemove(file, fileList) {
      return this.$confirm(`确定移除 ${file.name}？`);
    },

    // 加减分
    cancelQuXiao() {
      this.dialogFormVisible2 = false;
      if (this.jia === true) {
        this.jia = false;
      } else {
        this.jian = false;
      }
    },
    queding() {
      this.$refs["form3"].validate((valid) => {
        if (valid) {
          this.dialogFormVisible2 = false;
          this.jian = false;
          this.jia = false;
        }
      });
    },
    //加分减分
    openJajian(a) {
      this.dialogFormVisible2 = true;
      if (a === 1) {
        this.jia = true;
        console.log("form3", this.form3);
      } else {
        this.jian = true;
      }
    },
    //主裁判提交打分
    submitRefferJudge() {
      console.log("当前行id" + this.nowRowid);
      refferScore(this.nowRowid, this.orderId).then((res) => {
        if (res.code === 200) {
          // let judge = res.data.filter((item) => {
          //   return item.type === "裁判长";
          // });
          if (this.form3.averageScore <= 0) {
            this.$message({
              type: "error",
              message: "主裁还为打分，不能提交打分!",
            });
          } else {
            this.form3.score = this.sumNum;
            submitScore(this.form3).then((res) => {
              if (res.code === 200) {
                refferScore(this.nowRowid, this.orderId).then((res) => {
                  if (res.code === 200) {
                    this.ScoreInfo = res.data
                      .filter(
                        (item) =>
                          !(item.type === "裁判长" || item.type === "副裁判长")
                      )
                      .sort((a, b) => a.type.localeCompare(b.type, "zh-CN"));
                    //裁判长分数
                    this.form3 = JSON.parse(
                      JSON.stringify(
                        res.data.filter((i) => i.type === "裁判长")[0]
                      )
                    );
                  }
                  this.$message({
                    type: "success",
                    message: "修改成功!",
                  });
                });
              }
            });
          }
          getShunxu(this.orderId).then((res) => {
            this.tableData = res.data.applyProjects;
          });
        }
      });
    },
    //选取行改变裁判分数
    rowScore(row, column, e) {
      //加分减分重置
      // this.form3.addScore = 0;
      // this.form3.reduceScore = 0;
      // console.log(row, column, e);
      this.form3 = {};
      this.RefferScoreTitle =
        row.type +
        "-" +
        row.projectName +
        "-" +
        row.groups +
        "-" +
        row.teamName;
      this.nowRowid = row.id;
      refferScore(row.id, this.orderId).then((res) => {
        if (res.code === 200) {
          this.ScoreInfo = res.data
            .filter(
              (item) => !(item.type === "裁判长" || item.type === "副裁判长")
            )
            .sort((a, b) => a.type.localeCompare(b.type, "zh-CN"));

          //裁判长分数
          this.form3 = JSON.parse(
            JSON.stringify(res.data.filter((i) => i.type === "裁判长")[0])
          );

          //裁判长得分
          // if (
          //   parseFloat(this.mainReffer.score) !== 0 &&
          //   parseFloat(this.mainReffer.score - this.sumNum) > 0
          // ) {
          //   this.form3.addScore = parseFloat(this.mainReffer.score - this.sumNum);
          // } else if (
          //   parseFloat(this.mainReffer.score) !== 0 &&
          //   parseFloat(this.mainReffer.score - this.sumNum) < 0
          // ) {
          //   this.form3.reduceScore = parseFloat(
          //     this.mainReffer.score - this.sumNum
          //   );
          // }
          // console.log(this.ScoreInfo);
        }
      });
    },

    // editScore(item) {
    //   this.formScore.score = item.score;
    //   this.dialogFormVisible = true;
    //   this.formRefferInfo = {
    //     applyProjectId: item.applyProjectId,
    //     idCard: item.idCard,
    //     name: item.name,
    //     orderId: item.orderId,
    //     score: item.score,
    //     type: item.type,
    //   };
    // },
    //修改提交分数
    submitRefferScore() {
      this.$refs["formScore"].validate((valid) => {
        if (valid) {
          this.formRefferInfo.score = this.formScore.score;
          console.log(this.formRefferInfo);
          submitScore(this.formRefferInfo).then((res) => {
            if (res.code === 200) {
              refferScore(this.nowRowid, this.orderId).then((res) => {
                if (res.code === 200) {
                  this.ScoreInfo = res.data
                    .filter(
                      (item) =>
                        !(item.type === "裁判长" || item.type === "副裁判长")
                    )
                    .sort((a, b) => a.type.localeCompare(b.type, "zh-CN"));
                }
                this.$message({
                  type: "success",
                  message: "修改成功!",
                });
              });
            }
          });
          this.dialogFormVisible = false;
        }
      });
    },

    //评分
    score(row) {
      //场次id
      this.orderId = row.id;
      getShunxu(row.id).then((res) => {
        this.tableData = res.data.applyProjects;
        this.orderName = res.data.title;
        //获取比赛名称
        getplay(res.data.competitionId).then((res) => {
          this.competitionName = res.data.name;
        });
        this.nowRowid = res.data.applyProjects[0].id;
        //默认第一个出场的数据
        this.RefferScoreTitle =
          res.data.applyProjects[0].type +
          "-" +
          res.data.applyProjects[0].projectName +
          "-" +
          res.data.applyProjects[0].groups +
          "-" +
          res.data.applyProjects[0].teamName;
        refferScore(this.nowRowid, this.orderId).then((res) => {
          if (res.code === 200) {
            this.ScoreInfo = res.data
              .filter(
                (item) => !(item.type === "裁判长" || item.type === "副裁判长")
              )
              .sort((a, b) => a.type.localeCompare(b.type, "zh-CN"));

            //裁判长加减分
            // if (
            //   parseFloat(this.mainReffer.score) !== 0 &&
            //   parseFloat(this.mainReffer.score - this.sumNum) > 0
            // ) {
            //   this.form3.addScore = parseFloat(
            //     this.mainReffer.score - this.sumNum
            //   );
            // } else if (
            //   parseFloat(this.mainReffer.score) !== 0 &&
            //   parseFloat(this.mainReffer.score - this.sumNum) < 0
            // ) {
            //   this.form3.reduceScore = parseFloat(
            //     this.mainReffer.score - this.sumNum
            //   );
            // }
            //裁判长分数
            this.form3 = JSON.parse(
              JSON.stringify(res.data.filter((i) => i.type === "裁判长")[0])
            );
          }
        });

        //定时器获取分数
        this.timerReffer = setInterval(() => {
          console.log("定时器！");
          refferScore(this.nowRowid, this.orderId).then((res) => {
            if (res.code === 200) {
              this.ScoreInfo = res.data
                .filter(
                  (item) =>
                    !(item.type === "裁判长" || item.type === "副裁判长")
                )
                .sort((a, b) => a.type.localeCompare(b.type, "zh-CN"));
              //裁判长分数
              this.form3 = JSON.parse(
                JSON.stringify(res.data.filter((i) => i.type === "裁判长")[0])
              );
            }
          });
          //需要定时执行的代码
        }, 8000);
      });
      this.titleScore = "评分";
      this.openScore = true;
    },

    //关闭评分页
    closedScore() {
      clearInterval(this.timerReffer);
    },
    handleStart(index, row) {
      startScore(this.orderId, row.id).then((res) => {
        if (res.code === 200) {
          this.$message({
            type: "success",
            message: row.createBy + "开始打分!",
          });
          getShunxu(this.orderId).then((res) => {
            this.tableData = res.data.applyProjects;
          });
        }
      });
    },

    // 重新打分
    reStart(index, row) {
      reStartScore(this.orderId, row.id).then((res) => {
          console.log('重新开始打分',row)
        if (res.code === 200) {
          this.$message({
            type: "success",
            message: (row.createBy == null ? "" : row.createBy) + "开始打分!",
          });
          getShunxu(this.orderId).then((res) => {
            this.tableData = res.data.applyProjects;
          });
        }
      });
    },

    handleStop(index, row) {
      endScore(row.id).then((res) => {
        console.log('结束打分',row)
        if (res.code === 200) {
          this.$message({
            type: "success",
            message: (row.createBy == null ? "" : row.createBy) + "结束打分!",
          });
          getShunxu(this.orderId).then((res) => {
            this.tableData = res.data.applyProjects;
          });
        }
      });
    },
    handleGiveUp(index, row) {
      abstention(row.id).then((res) => {
        if (res.code === 200) {
          this.$message({
            type: "success",
            message: row.createBy + "已弃权!",
          });
          getShunxu(this.orderId).then((res) => {
            this.tableData = res.data.applyProjects;
          });
        }
      });
    },
    positionIndex(e) {
      if (this.tableData && this.tableData.length) {
        for (var i = 0; i < this.tableData.length; i++) {
          if (this.tableData[i].sort == e) {
            this.$refs["gameTable"].setCurrentRow(this.tableData[i]);
            var dom = this.$refs.gameTable.bodyWrapper;
            this.$nextTick(() => {
              console.log(e);
              if (e > 2) {
                dom.scrollTo(0, 57 * (e - 2));
              } else {
                return;
              }
            });
            return;
          }
        }
        this.$message.error("未找到相关数据");
        // this.scanData = null;
        // this.$refs.scanDataRef.focus();
        return;
      }
    },
    getElementTop(element) {
      console.log("element", element);
      var actualTop = element.offsetTop;
      var current = element.offsetParent;
      while (current !== null) {
        actualTop += current.offsetTop;
        current = current.offsetParent;
      }
      return actualTop;
    },
    // open() {
    //   this.$confirm("此操作将提交打分, 是否继续?", "提示", {
    //     confirmButtonText: "提交",
    //     cancelButtonText: "取消",
    //     type: "warning",
    //   })
    //     .then(() => {
    //       this.$message({
    //         type: "success",
    //         message: "打分成功!",
    //       });
    //     })
    //     .catch(() => {
    //       this.$message({
    //         type: "info",
    //         message: "取消打分",
    //       });
    //     });
    // },
    //  正在进行操作
    getListGoing() {
      this.loading = true;
      this.queryGoingParams.status = "进行中";
      listShunxu(this.queryGoingParams).then((response) => {
        this.goingList = response.data.list;
        this.total2 = response.data.totalCount;
        this.loading = false;
      });
    },

    // 修改场次状态
    handleClick(row, command) {
      if (command === "进行中") {
        getOrderReffers(row.id).then((res) => {
          if (!res.data.artisticJudges) {
            this.$modal.msgError("请先设置裁判！");
          } else {
            startOrder(row.id).then((res) => {
              this.$modal.msgSuccess("修改场次状态为" + command);
              this.getList();
              this.getListGoing();
            });
          }
        });
      } else if (command === "结束") {
        endOrder(row.id).then((res) => {
          this.$modal.msgSuccess("修改场次状态为" + command);
          this.getList();
          this.getListGoing();
        });
      }

      // getShunxu(row.id).then((response) => {
      //   this.form = response.data;
      //   this.form.status = command;
      //   console.log(this.form);
      //   updateShunxu(this.form).then((response) => {
      //     this.$modal.msgSuccess("修改状态为" + command);
      //     this.getList();
      //     this.getListGoing();
      //   });
      // });
    },
    submitFormReffer(formName) {
      if (this.dynamicValidateForm.artisticJudges.length < 8) {
        this.$message("请继续添加裁判 最少数量8");
      } else {
        this.$refs[formName].validate((valid) => {
          if (valid) {
            console.log(this.dynamicValidateForm);
            setReffer(this.dynamicValidateForm).then((res) => {
              console.log('裁判场次',this.dynamicValidateForm)
              if (res.code == 200) {
                this.$modal.msgSuccess("添加成功！");
                this.openReffer = false;
                this.getList();
              }
            });
          } else {
            console.log("error submit!!");
            return false;
          }
        });
      }
    },
    // resetFormReffer(formName) {
    //   this.resetForm(formName);
    // },

    reset2() {
      this.dynamicValidateForm = {
        orderId: "",
        artisticJudges: [
          {
            name: "",
            idCard: "",
            type: "",
          },
        ],
        refferJudge: {
          name: "",
          idCard: "",
          type: "裁判长",
        },
        deputyReferees: [
          {
            name: "",
            idCard: "",
            type: "副裁判长",
          },
        ],
      };
      this.resetForm("dynamicValidateForm");
    },
    removeDomain(rowIndex) {
      // var index = this.dynamicValidateForm.artisticJudges.indexOf(item);
      // if (index !== -1) {

      // }
      let newRowData = { name: "", value: "" };
      // this.$set(this.dynamicValidateForm.artisticJudges, rowIndex, newRowData);
      this.dynamicValidateForm.artisticJudges.splice(rowIndex, 1);
    },
    addDomain() {
      if (this.dynamicValidateForm.artisticJudges.length >= 10) {
        this.$message("最多只能添加10个裁判!");
      } else {
        this.dynamicValidateForm.artisticJudges.push({
          name: "",
          idCard: "",
          type: "",
        });
      }
    },

    //新增副裁判长
    addDeputyReferee() {
      console.log(this.dynamicValidateForm.deputyReferees);
      this.dynamicValidateForm.deputyReferees.push({
        name: "",
        idCard: "",
        type: "副裁判长",
      });
    },

    //清空副裁判长
    removeDeputyReferee(rowIndex) {
      // var index = this.dynamicValidateForm.artisticJudges.indexOf(item);
      // if (index !== -1) {

      // }
      // let newRowData = { name: "", value: "" };
      // this.$set(this.dynamicValidateForm.deputyReferees, rowIndex, newRowData);
      this.dynamicValidateForm.deputyReferees.splice(rowIndex, 1);
    },

    // 裁判设置
    refereeSetup(row) {
      this.reset2();
      const id = row.id || this.ids;
      let refferType = row.formula;
      console.log(refferType);
      if (refferType.indexOf("竞技") != -1) {
        this.options = [
          {
            value: "艺术裁判",
            label: "艺术裁判",
          },
          {
            value: "完成裁判",
            label: "完成裁判",
          },
          {
            value: "难度裁判",
            label: "难度裁判",
          },
        ];
      } else if (refferType.indexOf("健身操") != -1) {
        this.options = [
          {
            value: "艺术裁判",
            label: "艺术裁判",
          },
          {
            value: "完成裁判",
            label: "完成裁判",
          },
        ];
      } else {
        this.options = [
          {
            value: "普通裁判",
            label: "普通裁判",
          },
        ];
      }
      //查询裁判 数据
      getOrderReffers(id).then((res) => {
        if (res.code == 200) {
          if (res.data.refferJudge) {
            this.dynamicValidateForm.refferJudge = res.data.refferJudge;
          }
          if (res.data.artisticJudges) {
            this.dynamicValidateForm.artisticJudges = res.data.artisticJudges;
          }
          if (res.data.deputyReferees) {
            this.dynamicValidateForm.deputyReferees = res.data.deputyReferees;
          }
        }
      });
      this.openReffer = true;
      this.titleReffer = "裁判设置";
      this.dynamicValidateForm.orderId = id;
    },
    // 穿梭框
    //右侧选中
    choose(value) {
      console.log(555, value);
      this.item = value;
    },
    // chooseType(value) {
    //   this.$refs.myTransfer.$children[0].query = value;
    //   this.value2 = "";
    // },
    // chooseGroup(value) {
    //   this.value1 = "";
    //   this.$refs.myTransfer.$children[0].query = value;
    // },
    // clearSelect() {
    //   this.$refs.myTransfer.$children[0].query = "";
    //   this.value1 = "";
    //   this.value2 = "";
    // },
    //上移事件
    handleUp(item, index) {
      let self = this;
      item = self.item;
      if (item.length == 1) {
        self.selectValue.find((val, indexs, arr) => {
          if (val == item) {
            index = indexs;
          }
        });
        if (index == 0) {
          self.$message("没有上移的空间了");
          return;
        }
        //改变的数组
        let changeItem = JSON.parse(
          JSON.stringify(self.selectValue[index - 1])
        );
        console.log(33, changeItem);
        self.selectValue.splice(index - 1, 1);
        self.selectValue.splice(index, 0, changeItem);
      } else {
        self.$message.error("只能选择一条数据进行上下移动");
        return;
      }
    },
    //下移事件
    handleDown(item, index) {
      // let array = [0, 1, 2, 3, 4, 5, 6];
      // document.write("原数组为：" + array + "<br />");
      // array.splice(2, 1);
      // let arrBack = array.splice(3, 0, 8);
      // document.write("array：", array + "<br />");
      // document.write("arrBack：", arrBack);

      let self = this;
      item = self.item;
      if (item.length == 1) {
        //选中值的下标
        self.selectValue.find((val, indexs, arr) => {
          if (val == item) {
            index = indexs;
          }
        });
        if (index == self.selectValue.length - 1) {
          // 这里是length-1,因为下标值从0开始
          self.$message("没有下移的空间了");
          return;
        }
        let changeItem = JSON.parse(JSON.stringify(self.selectValue[index]));
        self.selectValue.splice(index, 1);
        self.selectValue.splice(index + 1, 0, changeItem);
      } else {
        self.$message.error("只能选择一条数据进行上下移动");
        return;
      }
    },

    /** 查询比赛列表 */
    getPlayList() {
      // this.loading = true;
      listplay(this.queryPlayParams).then((response) => {
        this.playList = response.data.list;
        console.log(this.playList);
      });
    },
    /** 查询顺序列表 */
    getList() {
      this.loading = true;
      listShunxu(this.queryParams).then((response) => {
        this.shunxuList = response.data.list;
        this.total = response.data.totalCount;
        this.loading = false;
      });
    },
    // 取消按钮
    cancel() {
      // this.nowCompetitionId = "";
      this.selectValue = [];
      this.applyList = [];
      this.clearProject();
      this.open = false;
      this.reset();
      this.getPlayList();
    },
    cancelReffer() {
      this.openReffer = false;
      this.reset2();
    },

    // 表单重置
    reset() {
      this.form = {
        id: null,
        competitionId: null,
        title: null,
        // status: null,
        startTime: null,
        applyProjectIds: null,
      };
      this.resetForm("form");
    },
    /** 搜索按钮操作 */
    handleQuery() {
      this.queryParams.page = 1;
      this.getList();
    },

    // 进行比赛搜素哦
    handleGoingQuery() {
      this.queryGoingParams.page = 1;
      this.getListGoing();
    },
    /** 重置按钮操作 */
    resetQuery() {
      (this.queryParams = {
        page: 1,
        rowsPerPage: 10,
        info: null,
        game: null,
        status: null,
        time: null,
      }),
        this.resetForm("queryForm");
      this.handleQuery();
      this.getPlayList();
    },
    resetGoingQuery() {
      this.resetForm("queryForm");
      this.handleGoingQuery();
      this.getPlayList();
    },
    // 多选框选中数据
    handleSelectionChange(selection) {
      this.ids = selection.map((item) => item.id);
      this.single = selection.length !== 1;
      this.multiple = !selection.length;
    },
    /** 新增按钮操作 */
    handleAdd() {
      if (!this.queryParams.competitionId) {
        this.$modal.msgError("请先选择赛事");
      } else {
        this.nowCompetitionId = this.queryParams.competitionId;
        this.reset();
        getplay(this.nowCompetitionId).then((res) => {
          this.groups = res.data.groups.split(",");
          this.projects = res.data.projects;
        });
        this.selectApply2();
        this.open = true;
        this.form.type = "常规";

        this.title = "添加顺序";
      }
      this.getPlayList();
    },

    selectApply2() {
      const dataInfo = {
        competitionId: this.nowCompetitionId,
        projectId: "",
        group: "",
      };
      getApplys(dataInfo).then((res) => {
        if (res.data.length > 0) {
          this.applyList = res.data;
          console.log("apply========", this.applyList);
        }
      });
    },
    /** 修改按钮操作 */
    handleUpdate(row) {
      const loading = this.$loading({
        lock: true,
        text: "Loading",
        spinner: "el-icon-loading",
        background: "rgba(0, 0, 0, 0.7)",
      });

      this.reset();
      const id = row.id || this.ids;

      getShunxu(id)
        .then((response) => {
          this.nowCompetitionId = response.data.competitionId;
          getplay(this.nowCompetitionId).then((res) => {
            this.groups = res.data.groups.split(",");
            this.projects = res.data.projects;
          });
          if (response.data.applyProjectIds) {
            this.selectValue = response.data.applyProjectIds.split(",");
          }
          this.form = response.data;

          if (response.data.applyProjects !== null) {
            console.log("+++++");
            this.finishOrder = response.data.applyProjects;
          }

          // this.$nextTick(function () {
          // this.applyList = this.applyList.concat(this.finishOrder);
          // });
          const dataInfo = {
            competitionId: this.nowCompetitionId,
            projectId: "",
            group: "",
          };
          getApplys(dataInfo).then((res) => {
            if (res.data.length > 0) {
              this.applyList = res.data;
            }
            if (this.finishOrder !== undefined && this.finishOrder.length > 0) {
              this.finishOrder.map((item) => {
                this.applyList.push(item);
              });
            }
            loading.close();
            this.open = true;
          });

          this.title = "修改顺序";
        })
        .catch(() => {
          loading.close();
        });
    },
    /** 提交按钮 */
    submitForm() {
      this.$refs["form"].validate((valid) => {
        this.form.applyProjectIds = this.selectValue.join(",");
        this.form.competitionId = this.queryParams.competitionId;
        if (valid) {
          if (this.form.id != null) {
            updateShunxu(this.form).then((response) => {
              this.$modal.msgSuccess("修改成功");
              this.open = false;
              this.getList();
              this.getPlayList();
            });
          } else {
            addShunxu(this.form).then((response) => {
              this.$modal.msgSuccess("新增成功");
              this.open = false;
              this.getList();
              this.getPlayList();
            });
          }
        }
        this.clearProject();
      });
    },
    // 清空数据
    clearProject() {
      this.nowCompetitionId = "";
      this.finishOrder = [];
      this.selectValue = [];
      this.playList = [];
      this.group = "";
      this.projectId = "";
      this.applyList = [];
    },
    /** 删除按钮操作 */
    handleDelete(row) {
      const ids = row.id || this.ids;
      this.$modal
        .confirm('是否确认删除顺序编号为"' + ids + '"的数据项？')
        .then(function () {
          return delShunxu(ids);
        })
        .then(() => {
          this.getList();
          this.$modal.msgSuccess("删除成功");
        })
        .catch(() => {});
    },
    /** 导出按钮操作 */
    handleExport() {
      this.download(
        "system/shunxu/export",
        {
          ...this.queryParams,
        },
        `shunxu_${new Date().getTime()}.xlsx`
      );
    },

    // 导出出场顺序
    exportOrder(row) {
      if (!this.queryParams.competitionId) {
        this.$modal.msgError("请先选择赛事");
      } else {
        this.downloadFile(
          "/work/export/exportOrder",
          {
            competitionId: this.queryParams.competitionId,
            title: this.queryParams.title,
          },
          `出场顺序表_${
            new Date().getFullYear() +
            "-" +
            (new Date().getMonth() + 1) +
            "-" +
            new Date().getDate()
          }.xlsx`
        );
      }
    },

    exportAuthe(row) {
      if (!this.queryParams.competitionId) {
        this.$modal.msgError("请先选择赛事");
      } else {
        this.downloadFile(
          "/work/export/exportAthleteOrder",
          {
            competitionId: this.queryParams.competitionId,
            title: this.queryParams.title,
          },
          `运动员表_${
            new Date().getFullYear() +
            "-" +
            (new Date().getMonth() + 1) +
            "-" +
            new Date().getDate()
          }.xlsx`
        );
      }
    },

    //出场顺序模板表下载
    underOrder() {
      this.downloadFile(
        "/work/competition/downloadTemplate",
        null,
        `出场顺序模板.xlsx`
      );
    },
  },
};
</script>
<style scoped>
.edit_dev >>> .transfer-footer {
  margin-left: 20px;
  padding: 6px 5px;
}
.edit_dev >>> .el-transfer-panel__list.is-filterable {
  height: 159px;
  padding-top: 0;
}
.edit_dev >>> .el-transfer-panel {
  width: 420px;
}
.edit_dev >>> .el-transfer-panel__item.el-checkbox {
  height: 60px;
}
.edit_dev >>> .el-input--medium .el-input__inner {
  width: 208px;
}
.el-dropdown {
  vertical-align: top;
}
.el-dropdown + .el-dropdown {
  margin-left: 15px;
}
.el-icon-arrow-down {
  font-size: 12px;
}
.clearfix:before,
.clearfix:after {
  display: table;
  content: "";
}
.clearfix:after {
  clear: both;
}
.el-rate {
  height: 50px;
}
.el-rate__icon {
  font-size: 50px;
  margin-right: 6px;
  color: #c0c4cc;
  transition: 0.3s;
}
.bottom {
  margin-top: 13px;
  line-height: 12px;
  text-align: center;
  padding: 14px 0;
  font-size: 16px;
  color: #ffffff;
  font-weight: bold;
}
.el-col-lg-24-5 {
  width: 20%;
}
.el-col-lg-24-15 {
  width: 60%;
}
.already {
  background-color: #409eff;
}
.noready {
  background-color: #909399;
}
.headreferee {
  background-color: #67c23a;
}
.el-table--striped .el-table__body tr.el-table__row--striped.current-row td,
.el-table__body tr.current-row > td {
  color: #fff;
  background-color: #409eff !important;
}
.submit-score {
  display: flex;
  justify-content: center;
  align-items: center;
  height: 100%;
}
.titleName {
  line-height: 70px;
  text-align: center;
  font-size: 26px;
  font-weight: bold;
}
.titleName2 {
  line-height: 50px;
  text-align: center;
  font-size: 20px;
}
</style>